﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DrivingCRM.Controller;

namespace DrivingCRM.Views.Private.CRM
{
    public partial class ViewAgencyPlanning : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RS_Events.AppointmentStyleMode = Telerik.Web.UI.AppointmentStyleMode.Simple;

            if (HttpContext.Current.User.Identity.IsAuthenticated && Session["User"] != null)
            {
                if ((Session["User"] as List<string>)[0] == "Salesman")
                {
                    this.RS_Events.AllowDelete = true;
                }
                
                if ((Session["User"] as List<string>)[0] == "Stakeholder" ||
                    (Session["User"] as List<string>)[0] == "Client" || (Session["User"] as List<string>)[0] == "Salesman")
                {
                    this.DS_Agencies.Where = "it.IdAgency == @CurrentAgency";
                    this.DS_Agencies.WhereParameters.Add(new Parameter() { DbType = System.Data.DbType.Int32, Name = "CurrentAgency", DefaultValue = (Session["User"] as List<string>)[2] });
                    this.DDL_Agencies.Enabled = false;
                }
                else
                {
                    this.DDL_Agencies.Enabled = true;
                }

            }
            else
                Response.Redirect("~/Views/Default.aspx");
        }

        protected void RS_Events_AppointmentInsert(object sender, Telerik.Web.UI.AppointmentInsertEventArgs e)
        {
            e.Cancel = true;
            Response.Redirect(Request.Url.AbsolutePath);
        }

        protected void RS_Events_AppointmentDelete(object sender, Telerik.Web.UI.AppointmentDeleteEventArgs e)
        {
            int idEvent = 0;
            bool ret = false;

            if (int.TryParse(e.Appointment.ID.ToString(), out idEvent))
                ret = EntityManager.DeleteEvent(idEvent);

            Response.Redirect(Request.Url.AbsolutePath);
        }
    }
}